<template>
  <div>
    <div>
      <Row class="header" type="flex" justify="start">
        <Col span="24">
          <Icon class="icon" type="ios-podium-outline"/>
          <span class="title">员工业务受理量统计</span>
        </Col>
      </Row>
      <br>
      <div id="staffAcceptance" :style="{ width: width + 'px', height: height + 'px'}"></div>
    </div>
    <div>
      <Modal v-model="workModalInfo.show" :title="workModalInfo.title" width="1000">
        <Table border :columns="workInfoColumns" :data="workInfoList" ref="table3" style="margin-top: 30px"></Table>
        <Row v-if="workModalInfo.loading == true">
          <Col class="demo-spin-col" span="8" offset="8">
            <Spin fix>
              <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
              <div>数据正在加载</div>
            </Spin>
          </Col>
        </Row>
        <Page :total="workModalInfo.totalRecord" class="page_style" :current="workModalInfo.pageNo"
              :page-size="workModalInfo.pageSize" @on-change="changePageNo" show-total show-elevator show-sizer @on-page-size-change="changePagesize"/>
      </Modal>
    </div>
  </div>
</template>

<script>
import echarts from 'echarts'
import { getPersonWorkList } from '@/api/eventlist'
export default {
  name: 'StaffAcceptanceEchart',
  data () {
    return {
      chartData: [],
      workInfoColumns: [
        { title: '序号', type: 'index', key: 'index', width: 60, align: 'center' },
        { title: '事项名称', key: 'title', width: 100, align: 'center' },
        { title: '办理社区', key: 'sq_name_all', align: 'center' },
        { title: '办理时间', key: 'create_time', width: 170, align: 'center' },
        { title: '办理状态', key: 'process_name', width: 110, align: 'center' },
        { title: '申请人姓名', key: 'name', width: 110, align: 'center' },
        { title: '申请人证件号', key: 'cardno', width: 170, align: 'center' },
        { title: '联系方式', key: 'mobile', width: 150, align: 'center' }
      ],
      workInfoList: [],
      workModalInfo: {
        show: false, loading: true, pageNo: 1, pageSize: 10, currentPageNo: 1, currentPageSize: 10, yg_name: ''
      }
    }
  },
  props: {
    width: {
      type: Number,
      default: () => {
        return 500
      }
    },
    height: {
      type: Number,
      default: () => {
        return 300
      }
    }
  },
  mounted () {
  },
  methods: {
    chart (data) {
      this.chartData = data
      let option = {
        title: {
          text: ''
        },
        textStyle: {
          color: '#bababa'
        },
        legend: {},
        tooltip: {
          trigger: 'axis',
          backgroundColor: 'rgba(50,50,50,0.6)',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        dataset: {
          dimensions: ['yg_name_all', 'acceptancenum'],
          source: []
        },
        yAxis: {
          name: '单位：办件数',
          type: 'value',
          axisLine: {
            lineStyle: {
              color: '#bababa' // 轴及其文字颜色
            }
          }
        },
        xAxis: {
          type: 'category',
          axisLabel: {
            interval: 0,
            rotate: 40
          },
          axisLine: {
            lineStyle: {
              color: '#bababa' // 轴及其文字颜色
            }
          }
        },
        grid: {
          y: 50,
          y2: 100
        },
        series: [
          {
            name: '业务受理量',
            type: 'bar',
            label: {
              normal: {
                show: false,
                position: 'inside',
                color: ['#fff']
              }
            },
            itemStyle: {
            // 通常情况下：
              normal: {
                color: ['#FF4F98DF']
              },
              // 鼠标悬停时：
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
      this.chartData.forEach(item => {
        // area为空的是之前导入的数据（暂不显示）
        if (item.yg_name_all) {
          option.dataset.source.push(item)
        }
      })
      let myChart = echarts.init(document.getElementById('staffAcceptance'))
      myChart.setOption(option)
      // console.log(option)
      let that = this
      myChart.on('click', function (params) {
        that.workModalInfo.show = true
        that.workModalInfo.yg_name = params.data.create_by
        console.log(that.workModalInfo)
        that.init()
      })
    },
    init () {
      this.workInfoList = []
      this.workModalInfo.loading = true
      let param = {
        'yg_name': this.workModalInfo.yg_name,
        'pageNo': this.workModalInfo.currentPageNo,
        'pageSize': this.workModalInfo.currentPageSize
      }
      console.log(param)
      getPersonWorkList(param).then(ret => {
        if (ret.data.errcode === 0) {
          this.workModalInfo.loading = false
          this.workModalInfo.totalRecord = ret.data.data.totalRecord
          this.workInfoList = ret.data.data.results
        } else {
          this.$Notice.error({
            title: '查询失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    changePagesize (pageSize) {
      this.workModalInfo.currentPageSize = pageSize
      this.changePageNo()
    },
    changePageNo (pageNo) {
      this.workModalInfo.currentPageNo = pageNo
      this.init()
    }
  }
}
</script>

<style scoped>
  .header {
    height: 30px;
  }

  .icon {
    font-size: 28px;
    font-weight: 600;
    margin-right: 5px;
  }

  .title {
    font-size: 16px;
    font-weight: 600;
    line-height: 30px;
  }
</style>
